<?php
/* QQ:34734852
 * 业务联系：小鱼
 */
class Dir{
	public static function Run() {
		Dir::APP(); //项目目录
		Dir::File(); //生成默认文件
	}
	
	private static function APP(){
	 if ( !file_exists( ROOT . APP . '/Lock/GenerateLock.Lock' ) ) {
		is_dir( ROOT . APP )                                  or mkdir( ROOT . APP, '0777' );
		is_dir( ROOT . APP . '/Lock' )                        or mkdir( ROOT . APP . '/Lock' );
		is_dir( ROOT . APP . '/Action' )                      or mkdir( ROOT . APP . '/Action' );
		is_dir( ROOT . APP . '/Action/' . AREA )              or mkdir( ROOT . APP . '/Action/' . AREA );
		is_dir( ROOT . APP . '/Cache' )                       or mkdir( ROOT . APP . '/Cache' );
		is_dir( ROOT . APP . '/TTF' )                         or mkdir( ROOT . APP . '/TTF' );
		is_dir( ROOT . APP . '/SelCache' )                    or mkdir( ROOT . APP . '/SelCache' );
		is_dir( ROOT . APP . '/Class' )                       or mkdir( ROOT . APP . '/Class' );
		is_dir( ROOT . APP . '/Function' )                    or mkdir( ROOT . APP . '/Function' );
		is_dir( ROOT . APP . '/Config' )                      or mkdir( ROOT . APP . '/Config' );
		is_dir( ROOT . APP . '/Template' )                    or mkdir( ROOT . APP . '/Template' );
		is_dir( ROOT . APP . '/Log' )                         or mkdir( ROOT . APP . '/Log' );
		is_dir( ROOT . APP . '/Template/Default' )            or mkdir( ROOT . APP . '/Template/Default' );
		is_dir( ROOT . APP . '/Template/Default/Css' )        or mkdir( ROOT . APP . '/Template/Default/Css' );
		is_dir( ROOT . APP . '/Template/Default/Images' )     or mkdir( ROOT . APP . '/Template/Default/Images' );
		is_dir( ROOT . APP . '/Template/Default/JavaScript' ) or mkdir( ROOT . APP . '/Template/Default/JavaScript' );
		is_dir( ROOT . APP . '/Upload' )                      or mkdir( ROOT . APP . '/Upload' );
		is_dir( ROOT . APP . '/Upload/Images' )               or mkdir( ROOT . APP . '/Upload/Images' );
		is_dir( ROOT . APP . '/Upload/File' )                 or mkdir( ROOT . APP . '/Upload/File' );
		is_dir( ROOT . APP . '/Upload/ZipRar' )               or mkdir( ROOT . APP . '/Upload/ZipRar' );
		is_dir( ROOT . APP . '/Upload/Video' )                or mkdir( ROOT . APP . '/Upload/Video' );
		file_put_contents( ROOT . APP . '/Lock/GenerateLock.Lock', 'In the ' . date('Y-m-d') . ' project has been successfully generated, such as the need to re generate, please refresh the page to delete this file.' );
	 }
	}
	
	
	private static function File() {
	   if ( !file_exists( ROOT . APP . '/Lock/DefaultFile.Lock' ) ) {
		   
		   if ( !file_exists( ROOT . APP . '/Config/Config.ini.php' ) ) {
			   file_put_contents( ROOT . APP . '/Config/Config.ini.php', file_get_contents( PATH . 'Template/Config.tpl') );
		   }
		   
		   if ( !file_exists( ROOT . APP . '/Config/App.Config.php' ) ) {
			   file_put_contents( ROOT . APP . '/Config/App.Config.php', file_get_contents( PATH . 'Template/App.Config.tpl') );
		   }
		   
		   if ( !file_exists( ROOT . APP . '/Action/' . AREA . '/Load.Class.php' ) ) {
			   file_put_contents( ROOT . APP . '/Action/' . AREA . '/Load.Class.php', str_replace('+', AREA,  file_get_contents( PATH . 'Template/core.tpl')));
		   }
		   
		   if ( !file_exists( ROOT . APP . '/Action/' . AREA . '/' .  MODU . 'Action.Class.php' ) ) {
			   file_put_contents( ROOT . APP . '/Action/' . AREA . '/' .  MODU . 'Action.Class.php', str_replace('+', MODU,  str_replace('EyouPHP', AREA, file_get_contents( PATH . 'Template/index.tpl'))));
		   }
		   
		   if ( !file_exists( ROOT . APP . '/Template/Default/' . MODU . '.html' ) ){
			  file_put_contents( ROOT . APP . '/Template/Default/' . MODU . '.html', file_get_contents( PATH . 'Template/index.html.tpl')); 
			  //file_put_contents( ROOT . APP . '/Template/Default/Images/hello.png', file_get_contents( PATH . 'Template/hello.tpl')); 
		   }
			
		   file_put_contents( ROOT . APP . '/Lock/DefaultFile.Lock', 'The default file is generated in the success of ' . date('Y-m-d') . ', such as the need to re generate, please delete this file, refresh the page.' );
		
	  }
	}
	
}
Dir::Run();
